<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>ReflectionProperty 类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="reflectionparameter.tostring.html">« ReflectionParameter::__toString</a></li>
      <li style="float: right;"><a href="reflectionproperty.clone.html">ReflectionProperty::__clone »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.reflection.html">反射</a></li>
    <li>ReflectionProperty 类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.reflectionproperty" class="reference">

 <h1 class="title">ReflectionProperty 类</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5, PHP 7, PHP 8)</p>


  <div class="section" id="reflectionproperty.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    <span class="classname"><strong class="classname">ReflectionProperty</strong></span> 类报告有关类属性的信息。
   </p>
  </div>


  <div class="section" id="reflectionproperty.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">ReflectionProperty</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.reflector.html" class="interfacename">Reflector</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 常量 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.reflectionproperty.html#reflectionproperty.constants.is-static"><var class="varname">IS_STATIC</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.reflectionproperty.html#reflectionproperty.constants.is-readonly"><var class="varname">IS_READONLY</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.reflectionproperty.html#reflectionproperty.constants.is-public"><var class="varname">IS_PUBLIC</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.reflectionproperty.html#reflectionproperty.constants.is-protected"><var class="varname">IS_PROTECTED</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.reflectionproperty.html#reflectionproperty.constants.is-private"><var class="varname">IS_PRIVATE</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">string</span>
      <var class="varname"><a href="class.reflectionproperty.html#reflectionproperty.props.name">$<var class="varname">name</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">string</span>
      <var class="varname"><a href="class.reflectionproperty.html#reflectionproperty.props.class">$<var class="varname">class</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><span class="type">object</span>|<span class="type">string</span></span> <code class="parameter">$class</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$property</code></span>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">private</span> <span class="methodname"><a href="reflectionproperty.clone.html" class="methodname">__clone</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="reflectionproperty.export.html" class="methodname">export</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$class</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$return</code><span class="initializer"> = ?</span></span>): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getattributes.html" class="methodname">getAttributes</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$name</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getdeclaringclass.html" class="methodname">getDeclaringClass</a></span>(): <span class="type"><a href="class.reflectionclass.html" class="type ReflectionClass">ReflectionClass</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getdefaultvalue.html" class="methodname">getDefaultValue</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getdoccomment.html" class="methodname">getDocComment</a></span>(): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getmodifiers.html" class="methodname">getModifiers</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getname.html" class="methodname">getName</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.gettype.html" class="methodname">getType</a></span>(): <span class="type"><span class="type">?</span><span class="type"><a href="class.reflectiontype.html" class="type ReflectionType">ReflectionType</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.getvalue.html" class="methodname">getValue</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">object</span><span class="type"></span></span> <code class="parameter">$object</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.hasdefaultvalue.html" class="methodname">hasDefaultValue</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.hastype.html" class="methodname">hasType</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isdefault.html" class="methodname">isDefault</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isinitialized.html" class="methodname">isInitialized</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">object</span><span class="type"></span></span> <code class="parameter">$object</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isprivate.html" class="methodname">isPrivate</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.ispromoted.html" class="methodname">isPromoted</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isprotected.html" class="methodname">isProtected</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.ispublic.html" class="methodname">isPublic</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isreadonly.html" class="methodname">isReadOnly</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.isstatic.html" class="methodname">isStatic</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.setaccessible.html" class="methodname">setAccessible</a></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$accessible</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.setvalue.html" class="methodname">setValue</a></span>(<span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.setvalue.html" class="methodname">setValue</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="reflectionproperty.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>

   }</div>


  </div>

  

  <div class="section" id="reflectionproperty.props">
   <h2 class="title">属性</h2>
   <dl>
    
     <dt id="reflectionproperty.props.name"><var class="varname">name</var></dt>

     <dd>

      <p class="para">
       属性名。只读，在尝试赋值的时候抛出 <span class="classname"><a href="class.reflectionexception.html" class="classname">ReflectionException</a></span>。
      </p>
     </dd>

    
    
     <dt id="reflectionproperty.props.class"><var class="varname">class</var></dt>

     <dd>

      <p class="para">
       定义的属性所在的类。只读，在尝试赋值的时候抛出 <span class="classname"><a href="class.reflectionexception.html" class="classname">ReflectionException</a></span>。
      </p>
     </dd>

    
   </dl>

  </div>


  

  <div class="section" id="reflectionproperty.constants">
   <h2 class="title">预定义常量</h2>
   <div class="section" id="reflectionproperty.constants.modifiers">
    <h2 class="title">ReflectionProperty 修饰符</h2>
    <dl>

     
      <dt id="reflectionproperty.constants.is-static"><strong><code>ReflectionProperty::IS_STATIC</code></strong></dt>

      <dd>

       <p class="para">
        表示 <a href="language.oop5.static.html" class="link">static</a> 属性。在 PHP 7.4.0 之前，值为 <code class="literal">1</code>。
       </p>
      </dd>

     

     
      <dt id="reflectionproperty.constants.is-readonly"><strong><code>ReflectionProperty::IS_READONLY</code></strong></dt>

      <dd>

       <p class="para">
        表示 <a href="language.oop5.properties.html#language.oop5.properties.readonly-properties" class="link">readonly</a>
        属性。自 PHP 8.1.0 起可用。
       </p>
      </dd>

     

     
      <dt id="reflectionproperty.constants.is-public"><strong><code>ReflectionProperty::IS_PUBLIC</code></strong></dt>

      <dd>

       <p class="para">
        表示 <a href="language.oop5.visibility.html" class="link">public</a> 属性。在 PHP 7.4.0 之前，值为 <code class="literal">256</code>。
       </p>
      </dd>

     

     
      <dt id="reflectionproperty.constants.is-protected"><strong><code>ReflectionProperty::IS_PROTECTED</code></strong></dt>

      <dd>

       <p class="para">
        表示 <a href="language.oop5.visibility.html" class="link">protected</a> 属性。在 PHP 7.4.0 之前，值为 <code class="literal">512</code>。
       </p>
      </dd>

     

     
      <dt id="reflectionproperty.constants.is-private"><strong><code>ReflectionProperty::IS_PRIVATE</code></strong></dt>

      <dd>

       <p class="para">
        表示 <a href="language.oop5.visibility.html" class="link">private</a> 属性。在 PHP 7.4.0 之前，值为 <code class="literal">1024</code>。
       </p>
      </dd>

     

    </dl>

    <blockquote class="note"><p><strong class="note">注意</strong>: 
     <p class="para">
      这些常量的值可能会在不同 PHP 版本间发生更改。建议始终使用常量而不直接依赖值。
     </p>
    </p></blockquote>
   </div>
  </div>



 </div>

 



























































































































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="reflectionproperty.clone.html">ReflectionProperty::__clone</a> — Clone</li><li><a href="reflectionproperty.construct.html">ReflectionProperty::__construct</a> — Construct a ReflectionProperty object</li><li><a href="reflectionproperty.export.html">ReflectionProperty::export</a> — Export</li><li><a href="reflectionproperty.getattributes.html">ReflectionProperty::getAttributes</a> — Gets Attributes</li><li><a href="reflectionproperty.getdeclaringclass.html">ReflectionProperty::getDeclaringClass</a> — Gets declaring class</li><li><a href="reflectionproperty.getdefaultvalue.html">ReflectionProperty::getDefaultValue</a> — Returns the default value declared for a property</li><li><a href="reflectionproperty.getdoccomment.html">ReflectionProperty::getDocComment</a> — Gets the property doc comment</li><li><a href="reflectionproperty.getmodifiers.html">ReflectionProperty::getModifiers</a> — Gets the property modifiers</li><li><a href="reflectionproperty.getname.html">ReflectionProperty::getName</a> — Gets property name</li><li><a href="reflectionproperty.gettype.html">ReflectionProperty::getType</a> — Gets a property's type</li><li><a href="reflectionproperty.getvalue.html">ReflectionProperty::getValue</a> — Gets value</li><li><a href="reflectionproperty.hasdefaultvalue.html">ReflectionProperty::hasDefaultValue</a> — Checks if property has a default value declared</li><li><a href="reflectionproperty.hastype.html">ReflectionProperty::hasType</a> — Checks if property has a type</li><li><a href="reflectionproperty.isdefault.html">ReflectionProperty::isDefault</a> — Checks if property is a default property</li><li><a href="reflectionproperty.isinitialized.html">ReflectionProperty::isInitialized</a> — Checks whether a property is initialized</li><li><a href="reflectionproperty.isprivate.html">ReflectionProperty::isPrivate</a> — Checks if property is private</li><li><a href="reflectionproperty.ispromoted.html">ReflectionProperty::isPromoted</a> — Checks if property is promoted</li><li><a href="reflectionproperty.isprotected.html">ReflectionProperty::isProtected</a> — Checks if property is protected</li><li><a href="reflectionproperty.ispublic.html">ReflectionProperty::isPublic</a> — Checks if property is public</li><li><a href="reflectionproperty.isreadonly.html">ReflectionProperty::isReadOnly</a> — 检查属性是否为只读</li><li><a href="reflectionproperty.isstatic.html">ReflectionProperty::isStatic</a> — Checks if property is static</li><li><a href="reflectionproperty.setaccessible.html">ReflectionProperty::setAccessible</a> — Set property accessibility</li><li><a href="reflectionproperty.setvalue.html">ReflectionProperty::setValue</a> — Set property value</li><li><a href="reflectionproperty.tostring.html">ReflectionProperty::__toString</a> — To string</li></ul>
</div>
</div></div></body></html>